Questions
11 of 15
1What are the main categories of data types available in MySQL?
2What is the difference between CHAR and VARCHAR data types?
3Which data type would you use to store dates and times in MySQL?
4What is the difference between INT, FLOAT, and DECIMAL data types?
5What is the use of the TEXT and BLOB data types, and how are they different from VARCHAR?
6How does MySQL handle precision and scale in DECIMAL(M, D) columns internally, and how do these differ from FLOAT and DOUBLE in terms of storage and accuracy?
7When storing time zone–aware data, what are the differences in behavior and use cases between DATETIME, TIMESTAMP, and CONVERT_TZ() in MySQL?
8If you define a VARCHAR(255) column with utf8mb4 encoding, how does MySQL calculate the maximum possible storage size for that column, and how does it differ from CHAR(255)?
9What are the advantages and limitations of using ENUM and SET data types in terms of performance, flexibility, and schema evolution?
10Explain how MySQL internally stores and sorts values of type BLOB and TEXT. What happens when you try to index a TEXT column?
11How do signed and unsigned integer types affect query results, index usage, and storage size? Can you demonstrate an example where overflow behavior differs?
12In what scenarios would using a JSON column be preferable to a normalized table structure, and what are the internal storage and indexing implications of JSON in MySQL 8.0?
13How does MySQL’s BIT(M) type differ from BOOLEAN, TINYINT(1), and binary string types (BINARY, VARBINARY) in terms of storage, representation, and retrieval?
14If you define a composite index on multiple columns of different data types (e.g., INT, VARCHAR, and DATE), how do the internal data type differences influence sorting, comparisons, and index efficiency?
15What are the practical implications of using CHAR vs VARCHAR for columns in InnoDB tables with varying row lengths and frequent updates? How does this choice affect row fragmentation and performance?
11 / 15

How do signed and unsigned integer types affect query results, index usage, and storage size? Can you demonstrate an example where overflow behavior differs?

Signed vs Unsigned Integer Types in MySQL

MySQL integer types (TINYINT, SMALLINT, INT, BIGINT) can be defined as SIGNED or UNSIGNED. This affects the allowed range of values, how MySQL evaluates comparisons, how indexes are used, and what happens during overflow.

Key Differences Between SIGNED and UNSIGNED
  1. 1

    SIGNED integers allow negative values, while UNSIGNED integers only store 0 and positive values.

  2. 2

    UNSIGNED effectively doubles the maximum positive range (e.g., INT SIGNED max = 2,147,483,647 vs INT UNSIGNED max = 4,294,967,295).

  3. 3

    Indexing works the same structurally, but the value distribution affects query selectivity and performance.

  4. 4

    Comparisons behave differently when negative values are involved (SIGNED) vs always non-negative (UNSIGNED).

Impact on Storage Size
  1. 1

    Storage size is identical between SIGNED and UNSIGNED versions of the same type.

  2. 2

    Only the allowed numeric range differs; bytes used are the same.

  3. 3

    Example: INT (SIGNED or UNSIGNED) always uses 4 bytes.

Impact on Query Results & Index Usage
  1. 1

    UNSIGNED indexes may provide better selectivity when the dataset contains large positive-only values.

  2. 2

    Comparisons between SIGNED and UNSIGNED columns may cause implicit type conversion, reducing index usage.

  3. 3

    Sorting differs because SIGNED sorts negatives first, while UNSIGNED always starts from 0.

Example: A SIGNED column can store −100 to 100, but UNSIGNED cannot store negative numbers; attempts will cause errors or wrap-around.

Overflow Behavior Example (SIGNED vs UNSIGNED)
  1. 1

    SIGNED TINYINT range: −128 to 127

  2. 2

    UNSIGNED TINYINT range: 0 to 255

  3. 3

    Inserting 130 into SIGNED TINYINT overflows and wraps to −126

  4. 4

    Inserting −1 into UNSIGNED TINYINT becomes 255 (wrap-around)

Example: Demonstrating Overflow

Result: a = -126 and b = 255 due to wrapping behavior.